import urllib.request



url='https://www.baidu.com/s?ie=UTF-8&wd=ip'

headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36'
}

# 请求对象的定制
request = urllib.request.Request(url=url,headers=headers)

# 模拟浏览器访问服务器
# response = urllib.request.urlopen(request)

proxies={
    'http':'120.194.55.139:	6969'
}
handler = urllib.request.ProxyHandler(proxies=proxies)
opener = urllib.request.build_opener(handler)
response = opener.open(request)

# 获取响应信息
content = response.read().decode('utf-8')
# 保存
with open('daili.html','w',encoding='utf-8') as  fp:
    fp.write(content)
# handler bulid_opener open
# handler = urllib.request.ProxyHandler(proxies=proxies)


